﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECONTACT.DataLayer
{
    public class LopData
    {
        DataService m_LopData = new DataService();

        public DataTable LayDsLop()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM LOP");
            m_LopData.Load(cmd);
            return m_LopData;
        }

        public void LuuLop(String Ten, String MaKhoiLop, String MaNamHoc, String MaGV)
        {
            SqlCommand cmd = new SqlCommand("sp_ThemLop");

            cmd.Parameters.Add("@Ten", SqlDbType.NVarChar).Value = Ten;
            cmd.Parameters.Add("@MaKhoiLop", SqlDbType.Int).Value = Convert.ToInt32(MaKhoiLop);
            cmd.Parameters.Add("@MaNamHoc", SqlDbType.Int).Value = Convert.ToInt32(MaNamHoc);
            cmd.Parameters.Add("@MaGV", SqlDbType.Int).Value = Convert.ToInt32(MaGV);

            m_LopData.LoadProc(cmd);
        }

        public void UpdateLop(String MaLop, String Ten, String MaKhoiLop, String MaNamHoc, String MaGV)
        {
            SqlCommand cmd = new SqlCommand("sp_CapNhatLop");

            cmd.Parameters.Add("@MaLop", SqlDbType.NVarChar).Value = MaLop;
            cmd.Parameters.Add("@Ten", SqlDbType.NVarChar).Value = Ten;
            cmd.Parameters.Add("@MaKhoiLop", SqlDbType.Int).Value = Convert.ToInt32(MaKhoiLop);
            cmd.Parameters.Add("@MaNamHoc", SqlDbType.Int).Value = Convert.ToInt32(MaNamHoc);
            cmd.Parameters.Add("@MaGV", SqlDbType.Int).Value = Convert.ToInt32(MaGV);

            m_LopData.LoadProc(cmd);
        }

        public void DeleteLop(String MaLop)
        {
            SqlCommand cmd = new SqlCommand("sp_XoaLop");

            cmd.Parameters.Add("@MaLop", SqlDbType.Int).Value = Convert.ToInt32(MaLop);

            m_LopData.LoadProc(cmd);
        }
    }
}
